package com.pattern.creational_pattern.builder_pattern;

/**
 * @Description  Another abstract builder
 * @Author Ping
 * @Date 2022/3/20 22:56
 **/
public abstract class MealNewBuilder {
    /**
     * let meal's attrs as the builder's attributes
     */
    protected String food ;
    protected String drink ;

    public MealNewBuilder() {
    }

    /**
     * chain programming could be used, since the return was current object
     * Chain, stream programming,
     * List lst = new ArrayList<>() ;
     * lst.stream()
     *         .forEach(e ->
     *         {}) ;
     * functional programming.
     * @return
     */
    public abstract MealNewBuilder buildFood() ;
    public  abstract MealNewBuilder buildDrink() ;
    public Meal buildMeal() {
        // construct a meal
        Meal meal = new Meal() ;
        // do null-checking.
        if (this.drink != null) {
            meal.setDrink(this.drink);
        }
        if (this.food != null) {
            meal.setFood(this.food);
        }
        return meal ;
    }

}
